package states;


import hypeerweb.Node;

public class DownPointingNodeState extends StandardNodeState 
{
    
    public String toString() 
    {
        return "Down Pointing Node State";
    }
    
    public NodeState getNextNodeState(Node n)
    {
        if(n.hasNoDownPointers())
        {
            return StandardNodeState.getSingleton();
        }
        else
        {
            return getSingleton();
        }
    }
    
    public static final int STATE_ID = 1;
    
    private static NodeState singleton = null;
    
    public static NodeState getSingleton()
    {
        if(singleton == null)
        {
            singleton = new DownPointingNodeState();
        }
        return singleton;
    }

    public NodeState getChildNodeState()
    {
        assert(false); // if we get here, we screwed up.
        return null;
    }
    public NodeState getParentNodeState()
    {
        return StandardNodeState.getSingleton();
    }

    public Node getNextNode(Node n) 
    {
        Node currNode = Node.NULL_NODE;
        for(Node node: n.getDownPointers())
        {
            if(node.getWebId().getValue() > currNode.getWebId().getValue())
            {
                currNode = node;
            }
        }
        return currNode;
    }
    
    public int getId()
    {
        return STATE_ID;
    }
}
